package cn.stu.cms.controller;

import cn.stu.cms.dto.PageDto;
import cn.stu.cms.pojo.Announcement;
import cn.stu.cms.service.AnnouncementService;
import cn.stu.cms.util.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * (Announcement)表控制层
 *
 * @author gh
 * @since 2023-07-20 14:38:50
 */
@RestController
@RequestMapping("/announcement")
@AllArgsConstructor
public class AnnouncementController {
    /**
     * 服务对象
     */
    private final AnnouncementService announcementService;

    /**
     * 查询全部数据
     *
     * @return 全部数据
     */
    @GetMapping("/page")
    public R<Page<Announcement>> getPage(PageDto<Announcement> pageDto, Announcement announcement) {
        return announcementService.getPage(pageDto, announcement);
    }

    /**
     * 新增数据
     *
     * @param announcement 实体对象
     * @return 新增结果
     */
    @PostMapping("/save")
    public R<Boolean> save(@RequestBody @Valid Announcement announcement) {
        return announcementService.add(announcement);
    }

    /**
     * 删除
     * 公告删除
     *
     * @param id 主键结合
     * @return 删除结果
     */
    @DeleteMapping("/delete/{id}")
    public R<Boolean> delete(@PathVariable Long id) {
        return announcementService.delete(id);
    }

    /**
     * 修改数据
     *
     * @param announcement 实体对象
     * @return 修改结果
     */
    @PutMapping("/edit")
    public R<Boolean> edit(@RequestBody @Valid Announcement announcement) {
        return announcementService.edit(announcement);
    }
}
